package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ScoreDetails;
import com.ruoyi.system.service.IScoreDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评分细则Controller
 *
 * @author zxx
 * @date 2025-01-14
 */
@RestController
@RequestMapping("/system/details")
public class ScoreDetailsController extends BaseController
{
    @Autowired
    private IScoreDetailsService scoreDetailsService;

    /**
     * 查询评分细则列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScoreDetails scoreDetails)
    {
        startPage();
        List<ScoreDetails> list = scoreDetailsService.selectScoreDetailsList(scoreDetails);
        return getDataTable(list);
    }

    /**
     * 导出评分细则列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:export')")
    @Log(title = "评分细则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoreDetails scoreDetails)
    {
        List<ScoreDetails> list = scoreDetailsService.selectScoreDetailsList(scoreDetails);
        ExcelUtil<ScoreDetails> util = new ExcelUtil<ScoreDetails>(ScoreDetails.class);
        util.exportExcel(response, list, "评分细则数据");
    }

    /**
     * 获取评分细则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:details:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scoreDetailsService.selectScoreDetailsById(id));
    }

    /**
     * 新增评分细则
     */
    @PreAuthorize("@ss.hasPermi('system:details:add')")
    @Log(title = "评分细则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoreDetails scoreDetails)
    {
        return toAjax(scoreDetailsService.insertScoreDetails(scoreDetails));
    }

    /**
     * 修改评分细则
     */
    @PreAuthorize("@ss.hasPermi('system:details:edit')")
    @Log(title = "评分细则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoreDetails scoreDetails)
    {
        return toAjax(scoreDetailsService.updateScoreDetails(scoreDetails));
    }

    /**
     * 删除评分细则
     */
    @PreAuthorize("@ss.hasPermi('system:details:remove')")
    @Log(title = "评分细则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scoreDetailsService.deleteScoreDetailsByIds(ids));
    }
}
